/*
* Copyright 2010 Competentum group
*
* Licensed under the GNU General Public License, Version 3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*      http://www.gnu.org/licenses/gpl.html
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.competentum.builders
{
	import com.competentum.exceptions.DuplicatingDataBuilderError;
	import com.competentum.lib.data.builders.AbstractDataBuilder;

	public class BuilderScope
	{
		public var id:String;
		
		private var _builders:Vector.<AbstractDataBuilder> = new Vector.<AbstractDataBuilder>();
		
		public function getBuilder(type:String):AbstractDataBuilder
		{
			for each (var builder:AbstractDataBuilder in _builders)
			{
				if (builder.type == type)
				{
					return builder;
				}
			}
			return null;
		}
		
		public function add(builder:AbstractDataBuilder):void
		{
			if (getBuilder(builder.type))
			{
				throw new DuplicatingDataBuilderError();
			}
			_builders.push(builder);
		}
		
		public function BuilderScope(id:String)
		{
			this.id = id;
		}
	}
}